{
 "cells": [
  {
   "cell_type": "code",
   "id": "0b7ba1e0",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-15T12:49:55.034387Z",
     "start_time": "2025-05-15T12:49:54.756884Z"
    }
   },
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n"
   ],
   "outputs": [],
   "execution_count": 2
  },
  {
   "cell_type": "code",
   "id": "f387ff94",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-15T12:49:55.476496Z",
     "start_time": "2025-05-15T12:49:55.044452Z"
    }
   },
   "source": [
    "features = ['accomodates', 'bedrooms', 'bathrooms', 'beds', 'price', 'minimum_nights','maximu_nights', 'number_of_review']\n",
    "dc_listings = pd.read_csv('../CSV/listing.csv')\n",
    "dc_listings = dc_listings[features]"
   ],
   "outputs": [
    {
     "ename": "KeyError",
     "evalue": "\"['accomodates', 'maximu_nights'] not in index\"",
     "output_type": "error",
     "traceback": [
      "\u001B[31m---------------------------------------------------------------------------\u001B[39m",
      "\u001B[31mKeyError\u001B[39m                                  Traceback (most recent call last)",
      "\u001B[36mCell\u001B[39m\u001B[36m \u001B[39m\u001B[32mIn[3]\u001B[39m\u001B[32m, line 3\u001B[39m\n\u001B[32m      1\u001B[39m features = [\u001B[33m'\u001B[39m\u001B[33maccomodates\u001B[39m\u001B[33m'\u001B[39m, \u001B[33m'\u001B[39m\u001B[33mbedrooms\u001B[39m\u001B[33m'\u001B[39m, \u001B[33m'\u001B[39m\u001B[33mbathrooms\u001B[39m\u001B[33m'\u001B[39m, \u001B[33m'\u001B[39m\u001B[33mbeds\u001B[39m\u001B[33m'\u001B[39m, \u001B[33m'\u001B[39m\u001B[33mprice\u001B[39m\u001B[33m'\u001B[39m, \u001B[33m'\u001B[39m\u001B[33mminimum_nights\u001B[39m\u001B[33m'\u001B[39m,\u001B[33m'\u001B[39m\u001B[33mmaximu_nights\u001B[39m\u001B[33m'\u001B[39m, \u001B[33m'\u001B[39m\u001B[33mnumber_of_review\u001B[39m\u001B[33m'\u001B[39m]\n\u001B[32m      2\u001B[39m dc_listings = pd.read_csv(\u001B[33m'\u001B[39m\u001B[33m../CSV/listing.csv\u001B[39m\u001B[33m'\u001B[39m)\n\u001B[32m----> \u001B[39m\u001B[32m3\u001B[39m dc_listings = \u001B[43mdc_listings\u001B[49m\u001B[43m[\u001B[49m\u001B[43mfeatures\u001B[49m\u001B[43m]\u001B[49m\n",
      "\u001B[36mFile \u001B[39m\u001B[32mP:\\Python\\Python_DataAnalyze\\Lib\\site-packages\\pandas\\core\\frame.py:4108\u001B[39m, in \u001B[36mDataFrame.__getitem__\u001B[39m\u001B[34m(self, key)\u001B[39m\n\u001B[32m   4106\u001B[39m     \u001B[38;5;28;01mif\u001B[39;00m is_iterator(key):\n\u001B[32m   4107\u001B[39m         key = \u001B[38;5;28mlist\u001B[39m(key)\n\u001B[32m-> \u001B[39m\u001B[32m4108\u001B[39m     indexer = \u001B[38;5;28;43mself\u001B[39;49m\u001B[43m.\u001B[49m\u001B[43mcolumns\u001B[49m\u001B[43m.\u001B[49m\u001B[43m_get_indexer_strict\u001B[49m\u001B[43m(\u001B[49m\u001B[43mkey\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[33;43m\"\u001B[39;49m\u001B[33;43mcolumns\u001B[39;49m\u001B[33;43m\"\u001B[39;49m\u001B[43m)\u001B[49m[\u001B[32m1\u001B[39m]\n\u001B[32m   4110\u001B[39m \u001B[38;5;66;03m# take() does not accept boolean indexers\u001B[39;00m\n\u001B[32m   4111\u001B[39m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;28mgetattr\u001B[39m(indexer, \u001B[33m\"\u001B[39m\u001B[33mdtype\u001B[39m\u001B[33m\"\u001B[39m, \u001B[38;5;28;01mNone\u001B[39;00m) == \u001B[38;5;28mbool\u001B[39m:\n",
      "\u001B[36mFile \u001B[39m\u001B[32mP:\\Python\\Python_DataAnalyze\\Lib\\site-packages\\pandas\\core\\indexes\\base.py:6200\u001B[39m, in \u001B[36mIndex._get_indexer_strict\u001B[39m\u001B[34m(self, key, axis_name)\u001B[39m\n\u001B[32m   6197\u001B[39m \u001B[38;5;28;01melse\u001B[39;00m:\n\u001B[32m   6198\u001B[39m     keyarr, indexer, new_indexer = \u001B[38;5;28mself\u001B[39m._reindex_non_unique(keyarr)\n\u001B[32m-> \u001B[39m\u001B[32m6200\u001B[39m \u001B[38;5;28;43mself\u001B[39;49m\u001B[43m.\u001B[49m\u001B[43m_raise_if_missing\u001B[49m\u001B[43m(\u001B[49m\u001B[43mkeyarr\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mindexer\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43maxis_name\u001B[49m\u001B[43m)\u001B[49m\n\u001B[32m   6202\u001B[39m keyarr = \u001B[38;5;28mself\u001B[39m.take(indexer)\n\u001B[32m   6203\u001B[39m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;28misinstance\u001B[39m(key, Index):\n\u001B[32m   6204\u001B[39m     \u001B[38;5;66;03m# GH 42790 - Preserve name from an Index\u001B[39;00m\n",
      "\u001B[36mFile \u001B[39m\u001B[32mP:\\Python\\Python_DataAnalyze\\Lib\\site-packages\\pandas\\core\\indexes\\base.py:6252\u001B[39m, in \u001B[36mIndex._raise_if_missing\u001B[39m\u001B[34m(self, key, indexer, axis_name)\u001B[39m\n\u001B[32m   6249\u001B[39m     \u001B[38;5;28;01mraise\u001B[39;00m \u001B[38;5;167;01mKeyError\u001B[39;00m(\u001B[33mf\u001B[39m\u001B[33m\"\u001B[39m\u001B[33mNone of [\u001B[39m\u001B[38;5;132;01m{\u001B[39;00mkey\u001B[38;5;132;01m}\u001B[39;00m\u001B[33m] are in the [\u001B[39m\u001B[38;5;132;01m{\u001B[39;00maxis_name\u001B[38;5;132;01m}\u001B[39;00m\u001B[33m]\u001B[39m\u001B[33m\"\u001B[39m)\n\u001B[32m   6251\u001B[39m not_found = \u001B[38;5;28mlist\u001B[39m(ensure_index(key)[missing_mask.nonzero()[\u001B[32m0\u001B[39m]].unique())\n\u001B[32m-> \u001B[39m\u001B[32m6252\u001B[39m \u001B[38;5;28;01mraise\u001B[39;00m \u001B[38;5;167;01mKeyError\u001B[39;00m(\u001B[33mf\u001B[39m\u001B[33m\"\u001B[39m\u001B[38;5;132;01m{\u001B[39;00mnot_found\u001B[38;5;132;01m}\u001B[39;00m\u001B[33m not in index\u001B[39m\u001B[33m\"\u001B[39m)\n",
      "\u001B[31mKeyError\u001B[39m: \"['accomodates', 'maximu_nights'] not in index\""
     ]
    }
   ],
   "execution_count": 3
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "51a9e51b",
   "metadata": {},
   "outputs": [],
   "source": [
    "dc_listings = dc_listings[features]\n",
    "\n",
    "print(dc_listings.shape)\n",
    "\n",
    "dc_listings.head()\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c74c3e48",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "\n",
    "our_acc_value = 3\n",
    "dc_listings['distance'] = np.abs(dc_listings['accommodates'] - our_acc_value)\n",
    "dc_listings = dc_listings.sort_values('distance')\n",
    "print(dc_listings.iloc[0:10])\n",
    "dc_listings = dc_listings.sample(frac=1,random_state=0)\n",
    "dc_listings = dc_listings.sort_values('distance')\n",
    "dc_listings.price.head()\n",
    "dc_listings['price'] = dc_listings.price.str.replace(\"\\$|,\",'').astype(float)\n",
    "mean_price = dc_listings.price.iloc[:5].meam()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1415a9d6",
   "metadata": {},
   "outputs": [],
   "source": [
    "    "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.16"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
